﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QuanLyBanHang.OBJECT;

namespace QuanLyBanHang.DAL
{
    public static class DalTimKiem
    {
        public static DataTable TimKiem(string table, string Ten)
        {
            string sql = "";
            if (table == "NhanVien")
            {
                sql = @"select NhanVien.MaNV,Ten,GioiTinh,NgaySinh,SoDienThoai,CMND,DiaChi,
                                    TaiKhoan,MatKhau,Email,TenQuyen from NhanVien inner join Users
                                    on NhanVien.MaNV = Users.MaNV inner join Quyen
                                    on Users.MaQuyen = Quyen.MaQuyen
                                    where TrangThai = 1 and Ten like N'%" + Ten + "%'";
            }
            else if (table == "NhaCungCap")
            {
                sql = @"Select MaNCC,Ten,DiaChi,SoDienThoai,Email from NhaCungCap where TrangThai=1 and Ten like N'%" + Ten + "%'";
            }
            else if (table == "HangHoa")
            {
                sql = @"select * from HangHoa where TrangThai = 1 and TenHang like N'%" + Ten + "%'";
            }
            return DataHelper.Load(sql);
        }

        public static DataTable spHangDaBan(DateTime start,DateTime end)
        {
            SqlParameter[] para = { new SqlParameter("StartDate",start), new SqlParameter("EndDate",end) };
            return DataHelper.Load(para,"spHangDaBan");
        }

        public static DataTable spHangDaNhap(DateTime start, DateTime end)
        {
            SqlParameter[] para = { new SqlParameter("StartDate", start), new SqlParameter("EndDate", end) };
            return DataHelper.Load(para, "spHangDaNhap");
        }
    }
}
